/*
 * TextPacketQueue.h
 *
 *  Created on: 2018年8月13日
 *      Author: zhengboyuan
 */

#ifndef TEXTPACKETQUEUE_H_
#define TEXTPACKETQUEUE_H_

#include "AVFramePtr.h"
#include <deque>
#include "TCriticalSection.h"


namespace av
{

class TextPacketQueue
{
public:
	typedef std::deque< AVPacketPtr >  PacketDeque;

	static const size_t	MAX_QUEUE_SIZE = 30;

public:
    TextPacketQueue();
    virtual ~TextPacketQueue();

	void clear();

	size_t size();

	bool empty();

	size_t push(AVPacketPtr& packet);

	AVPacketPtr pop();

	AVPacketPtr pop(int64_t pts);

	bool pop(int64_t pts, AVPacketPtr& pkt);

	void setMaxSize(size_t maxSize);

	bool popUntil(int64_t pts, AVPacketPtr& pkt);

protected:
	bool isMatched(AVPacketPtr& pkt, int64_t pts);

protected:
	PacketDeque	m_packets;
	comn::CriticalSection	m_cs;
	size_t	m_maxSize;

};

} /* namespace av */

#endif /* TEXTPACKETQUEUE_H_ */
